#include "HardFun5_1.h"

namespace Solver
{
/*
维度:5
范围:[-10000, 10000]
难度:非常难
最小化目标值 :1.690812E-24
最优解       :178.337562, -0.482098, -5.13499E-18, 8.087486, 0.021765
说明         :本函数来自下面参考[1]里的例子1。设计算法 最小化值必须小于0.07, 否则优化器算法不考虑
参考         :[1]程培澄,程培聪,王萌,等.非线性方程组求解器全局优化求解能力对比研究[J].计算机应用与软件, 2022, 39(10):1-10.DOI:10.3969/j.issn.1000-386x.2022.10.001.
*/

HardFun5_1::HardFun5_1():BaseFun(5, FunType_E::Hard5_1_E, DifficultyLevel_E::Hard_E, 1, "Hard5_1", "")
{
    //1. 最优解
    passY_ = 0.072;
    bestY_ = 1.481510394278603e-05;
    bestX_ << 178.337562, -0.482098, -5.13499E-18, 8.087486, 0.021765;

    //3. 设置初始求解范围[-10000,10000]
    setXRange(-10000, 10000);

    //4. 添加一些描述
    description_ = "本函数来自参考的例子1: 程培澄,程培聪,王萌,等.非线性方程组求解器全局优化求解能力对比研究[J].计算机应用与软件, 2022, 39(10):1-10.DOI:10.3969/j.issn.1000-386x.2022.10.001.";
}

HardFun5_1::~HardFun5_1()
{

}

value_t HardFun5_1::calcFun(const VectorXd_t &x)
{
    const vecValue_t a{80.0031, 202.5367,251.1455,340.0130,352.0136};
    const vecValue_t b{0.55, 1.45, 1.55, 2.75, 3.15};
    value_t sum(0), y;
    for (std::size_t i = 0; i != 5; ++i)
    {
        y = a[i] / (x[0] + x[1] * a[i] + x[2] * std::pow(a[i], x[3]) + std::exp(x[4] * a[i]));
        if (std::isnan(y) || std::isinf(y))
        {
            return std::numeric_limits<value_t>::max();
        }

        sum += std::pow(y - b[i], 2);
    }

    return sum;
}

}